package logic

import (
	"1-8zy/rpc/model/mysql"
	"context"
	"fmt"

	"1-8zy/rpc/internal/svc"
	"1-8zy/rpc/shop"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateGoodStatusLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateGoodStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateGoodStatusLogic {
	return &UpdateGoodStatusLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateGoodStatusLogic) UpdateGoodStatus(in *shop.UpdateGoodStatusRequest) (*shop.UpdateGoodStatusResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Good{}
	err := g.UpdateStatus(int(in.GoodId), int(in.Status))
	if err != nil {
		return nil, fmt.Errorf("修改错误")
	}
	return &shop.UpdateGoodStatusResponse{
		Success: true,
	}, nil
}
